<?php session_start();?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?php
if(isset($_SESSION['lang']))
    require_once "./language_files/invitations_" . $_SESSION['lang'] . ".php";
else
    require_once "./language_files/invitations_en.php";
?>
<html>
    <head>
        <link href="style3.css" rel="stylesheet" type="text/css" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
        <?php include "jquery.php";
        require_once "functions.php";
        ?>

        <?
        if(isset($_GET['role']))
        {
            $role=$_GET['role'];
            if($role == 'reviewer')
            {
                echo '<script type="text/javascript">'
                ,'function inviteR();'
                ,'</script>';
            }
            else if($role == 'organizer')
            {
                echo '<script type="text/javascript">'
                ,'function inviteO();'
                ,'</script>';
            }
            else if($role == 'author')
            {
                echo '<script type="text/javascript">'
                ,'function inviteA();'
                ,'</script>';
            }
        }
        ?>

        <script type="text/javascript">
            // when a link letter is clicked, this code sends to inviteOrganizers page that 
            //loads in this page's div element the conference id and the clicked letter
            function inviteO(){
                $(document).ready(function()
                {
                    conferenceID = $("#conference_id").val();
                    $.ajax({
                        type:"POST",
                        url: "inviteOrganizers.php",
                        data:{letter:"A",conference_id:conferenceID},
                        success: function(response)
                        {
                            document.getElementById("mydiv").innerHTML = response;
                        }
                    });
                
                    $("#lett a").bind("click", function(e)
                    {
                        e.preventDefault();
                        clicked_letter=$(this).html();
                    
                        $.ajax({
                            type:"POST",
                            url: "inviteOrganizers.php",
                            data:{letter:clicked_letter,conference_id:conferenceID},
                            success: function(response)
                            {
                                document.getElementById("mydiv").innerHTML = response;
                            }
                        });
                        return false;
                    });
                    return false;
                });
            }
			
            function inviteR(){
                $(document).ready(function()
                {
                    conferenceID = $("#conference_id").val();
                    $.ajax({
                        type:"POST",
                        url: "ReviewerInvitations.php",
                        data:{letter:"A",conference_id:conferenceID},
                        success: function(response)
                        {
                            document.getElementById("mydiv").innerHTML = response;
                        }
                    });
                
                    $("#lett a").bind("click", function(e)
                    {
                        e.preventDefault();
                        clicked_letter=$(this).html();
                    
                        $.ajax({
                            type:"POST",
                            url: "ReviewerInvitations.php",
                            data:{letter:clicked_letter,conference_id:conferenceID},
                            success: function(response)
                            {
                                document.getElementById("mydiv").innerHTML = response;
                            }
                        });
                        return false;
                    });
                    return false;
                });
            }
			
			
            function inviteA(){
                $(document).ready(function()
                {
                    conferenceID = $("#conference_id").val();
                    $.ajax({
                        type:"POST",
                        url: "AuthorInviataions.php",
                        data:{letter:"A",conference_id:conferenceID},
                        success: function(response)
                        {
                            document.getElementById("mydiv").innerHTML = response;
                        }
                    });
                
                    $("#lett a").bind("click", function(e)
                    {
                        e.preventDefault();
                        clicked_letter=$(this).html();
                    
                        $.ajax({
                            type:"POST",
                            url: "AuthorInviataions.php",
                            data:{letter:clicked_letter,conference_id:conferenceID},
                            success: function(response)
                            {
                                document.getElementById("mydiv").innerHTML = response;
                            }
                        });
                        return false;
                    });
                    return false;
                });
            }
            // function that enables the dropdown list of every checked box,
            // it takes the check box itself and the number of the check box in the list which is also the number of the dropdown list  in the list
            function enable(e, i)             {
                // if the check box is checked
                if(e.checked==true) 
                {
                    // get the id of the dropbox that corrosponds this check box and enable it
                    document.getElementById("Committees"+i).disabled=false; 
                }
                // if the check box is unchecked
                if(e.checked==false) 
                {
                    // get the id of the dropbox that corrosponds this check box and disable it
                    document.getElementById("Committees"+i).disabled=true; 
                }
            }
				
				
            //When the Done button in inviteOrganizers is clicked it calls this method
            //This method gets all the checked checkboxes and the values of their linked drop down lists and put them in 2 arrays and sent them back to
            //inviteOrganizerspage
            function InvitationDoneO()
            {
                members=[];
                values=[];
                conferenceID = $("#conference_id").val();
                $("input[type=checkbox]:checked").each(function()
                {
                    member=$(this).val();
                    value=$("select[class="+$(this).val()+"]").val();
                    members[members.length]=member;
                    values[values.length]=value;
                });
                $.ajax({
                    type:"POST",
                    url:"inviteOrganizers.php",
                    data:{member_ids:members,committees:values,conference_id:conferenceID},
                    success:function(response)
                    {
                        $("#mydiv").fadeOut(300,function()
                        {
                            $("#mydiv").html(response);
                            $("#mydiv").fadeIn(300);
                        });
                    }
                }
            );
            }
            function InvitationDoneR()
            {
                members=[];
                values=[];
                conferenceID = $("#conference_id").val();
                $("input[type=checkbox]:checked").each(function()
                {
                    member=$(this).val();
                    value=$("select[class="+$(this).val()+"]").val();
                    members[members.length]=member;
                    values[values.length]=value;
                });
                $.ajax({
                    type:"POST",
                    url:"ReviewerInvitations.php",
                    data:{member_ids:members,committees:values,conference_id:conferenceID},
                    success:function(response)
                    {
                        $("#mydiv").fadeOut(300,function()
                        {
                            $("#mydiv").html(response);
                            $("#mydiv").fadeIn(300);
                        });
                    }
                }
            );
            }
            function InvitationDoneA()
            {
                members=[];
                values=[];
                conferenceID = $("#conference_id").val();
                $("input[type=checkbox]:checked").each(function()
                {
                    member=$(this).val();
                    value=$("select[class="+$(this).val()+"]").val();
                    members[members.length]=member;
                    values[values.length]=value;
                });
                $.ajax({
                    type:"POST",
                    url:"AuthorInviataions.php",
                    data:{member_ids:members,committees:values,conference_id:conferenceID},
                    success:function(response)
                    {
                        $("#mydiv").fadeOut(300,function()
                        {
                            $("#mydiv").html(response);
                            $("#mydiv").fadeIn(300);
                        });
                    }
                }
            );
            }
        </script>
    </head>
    <body>

        <?php
        // the conference id from the previous page
        if(isset($_GET['conference_id']))
        {
            $confid=intval($_GET['conference_id']);
            $get_name=mysql_query("Select long_name From Conference Where conference_id = '$confid'") or die(mysql_error());
            $Get_name=mysql_fetch_assoc($get_name);
            $l_name=mysql_safe($Get_name['long_name']);
            echo "<h1>{$l_name}</h1>";

            if($role == 'reviewer')
            {
                echo "<h2>" . $lang['invite_reviewers'] . "</h2>";
            }
            if($role == 'organizer')
            {
                echo "<h2>" . $lang['invite_org'] . "</h2>";
            }
            if($role == 'author')
            {
                echo "<h2>" . $lang['invite_author'] . "</h2>";
            }
        }
        echo "<fieldset>";

        // an array of alphabets
        $alphabets=array('A','B','C','D','E','F','G','H','I','J','K','L'
            ,'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
        echo "<div id='lett'>";
        for($i=0; $i <= 25; $i++)
        { // loop on the 25 letters in the array
            $Letter=$alphabets[$i]; //save each letter in a variable 
            // make the letters links and when clicked it should send an ajax request to this page passing it the clicked letter   
            echo '<a href="#" onclick="javascript:AjaxRequest(this);">' . $Letter . '</a>&nbsp;';
        }
        echo "</div>";  // save the conference id in a variable 
        $confid=$_GET['conference_id'];
        // put the conference id in hidden input to get it in the javascript code in this page 
        echo '<input type="hidden" name="conference_id" id="conference_id" value="' . $confid . '"/> ';
        // }
        ?> 

        <div id="mydiv">

        </div>
    </fieldset>  
</body>
</html>
